# import asyncio
# import time
#
#
# async def job(t):
#     print('Start job ', t)
#     await asyncio.sleep(t)
#     print('Job', t, 'takes ', t, 's')
#
#
# async def main(loop):
#     tasks = [loop.create_task(job(t)) for t in range(10)]
#     await asyncio.wait(tasks)
#
#
# t1 = time.time()
# loop = asyncio.get_event_loop()
# loop.run_until_complete(main(loop))


# import aiohttp
# import asyncio
#
#
# async def job(session):
#     response = await session.get('https://www.baidu.com/')
#     return str(response.url)
#
#
# async def main(loop):
#     async with aiohttp.ClientSession() as session:
#         tasks = [loop.create_task(job(session)) for _ in range(2)]
#         finished, unfinished = await asyncio.wait(tasks)
#         all_results = [r.result() for r in finished]
#         print(all_results)
#
#
# loop = asyncio.get_event_loop()
# loop.run_until_complete(main(loop))
# loop.close()

# import asyncio
# import time
#
# async def job(t, num):
#     print('任务序号' + str(num) + '开始')
#     await asyncio.sleep(t)
#     print('任务序号' + str(num) + '结束')
#     return t + num
#
#
# async def main():
#     result = await asyncio.gather(job(1, 1), job(2, 2), job(3, 3))
#     print(result)
#
# start = time.time()
# asyncio.run(main())
# end = time.time()
# print(end - start)
#
#
# def job1(t,num):
#     print('任务序号' + str(num) + '开始')
#     time.sleep(t)
#     print('任务序号' + str(num) + '结束')
#     return t + num
#
# start = time.time()
# job1(1, 1)
# job1(2, 2)
# job1(3, 3)
# end = time.time()
# print(end - start)

import aiohttp
import asyncio

from aiohttp import ProxyConnector


async def download(session, url):
    async with session.get(url) as response:
        return await response.text()


async def main():
    async with aiohttp.ClientSession() as session:
        html = await download(session, 'http://baidu.com')
        print(html)


proxies = 'http://127.0.0.1:8888'
async with aiohttp.ClientSession(connector=ProxyConnector.from_url(proxies)) as session:
    ## 然后写一些操作逻辑
    pass
asyncio.run(main())  # 运行事件循环